package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.BindedDeviceBean
import com.zztl.infiniteBand.model.NoDataResponseBean
import com.zztl.infiniteBand.net.FilterSubscriber2
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.BindDeviceRequest
import com.zztl.infiniteBand.ui.view.mvpview.UploadImageView


/**
 * @desc
 * @auth ${user}
 * @time 2018/6/14  17:50
 */
class BindDevicePresenter : BasePresenter<UploadImageView>() {


    fun bindDevice(request: BindDeviceRequest, context: Context) {
        addSubscribe(RetorfitServiceManger.observe(RetorfitServiceManger.instance!!.apiService.bindDevice(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<NoDataResponseBean>(context) {
                    override fun success(bean: NoDataResponseBean) {
                        view!!.loadSuccess()
                    }

                    override fun fail(msg: String?) {
                        view!!.loadFail(msg)
                    }
                }))
    }

    fun getBindDevice(context: Context) {
        addSubscribe(RetorfitServiceManger.observe(RetorfitServiceManger.instance!!.apiService.getBindDeviceList(""))
                .subscribe(object : FilterSubscriber2<BindedDeviceBean>(context) {


                    override fun success(bean: BindedDeviceBean) {
                        view!!.getBindDeviceList(bean)
                    }

                    override fun fail(msg: String?) {
                        view!!.getBindDeviceFail()
                    }
                }))
    }
}
